package com.woyowodaows.utils;

import com.woyowodaows.application.MyApplication;
import com.woyowodaows.bean.mine.UserInfoBean;
import com.woyowodaows.dao.UserInfoBeanDao;

/**
 * @author haiwei
 *         用户信息缓存类
 *         2017/8/29
 */
public class CacheUserInfoUtils {


    /**
     * 将对象存缓存，注意该对象的类必须序列化
     *
     * @param infoBean     传递null则是清空缓存
     */
    public static void setUserInfo(UserInfoBean infoBean) {
        MyApplication.getDaoSession().getUserInfoBeanDao().deleteAll();
        if (infoBean != null){
            MyApplication.getDaoSession().getUserInfoBeanDao().insert(infoBean);
        }
    }

    /**
     * 获取缓存对象
     *
     * @return 返回null代表缓存不存在
     */
    public static UserInfoBean getUserInfo() {
        UserInfoBeanDao dao=MyApplication.getDaoSession().getUserInfoBeanDao();
        dao.detachAll();
        UserInfoBean infoBean = dao.load("userId");
        if(infoBean!=null){
            return infoBean;
        }else {
            UserInfoBean infoBeans=new UserInfoBean();
            return infoBeans;
        }
    }




}
